﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;

namespace TransferJsonAsString.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult ConvertJson(string jsonString)
        {
            Employee e = new Employee();

            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Employee));
            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
            {
                e = (Employee)ser.ReadObject(ms);
            }
            var e1 = JsonConvert.DeserializeAnonymousType(jsonString, e);

            return null;   
        }
    }

    public class Employee
    {
        public string ID { get; set; }

        public string Name { get; set; }
    }
}
